import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
  {
    path: '/login',
    meta: { title: '登录' },
    component: resolve => require(['page/login'], resolve)
  },
  {
    path: '/register',
    meta: { title: '注册' },
    component: resolve => require(['page/register'], resolve)
  },
  {
    path: '/register/next',
    meta: { title: '注册' },
    component: resolve => require(['page/register/next'], resolve)
  },
  {
    path: '/forget',
    meta: { title: '找回密码' },
    component: resolve => require(['page/forget'], resolve)
  },
  {
    path: '/forget/next',
    meta: { title: '注册' },
    component: resolve => require(['page/forget/next'], resolve)
  },
  {
    path: '/reset',
    meta: { title: '修改密码' },
    component: resolve => require(['page/passwordReset'], resolve)
  },
  {
    path: '/aboutus',
    meta: { title: '关于我们' },
    component: resolve => require(['page/aboutUs'], resolve)
  },
  {
    path: '/help',
    meta: { title: '购物咨询' },
    component: resolve => require(['page/helpCenter'], resolve)
  },
  {
    path: '/help/:id',
    component: resolve => require(['page/helpCenter/detail'], resolve)
  },
  {
    path: '/member/success',
    meta: { title: '支付成功', isAuth: true },
    component: resolve => require(['page/member/success'], resolve)
  },
  {
    path: '/member/pay',
    meta: { title: '支付', isAuth: true },
    component: resolve => require(['page/member/pay'], resolve)
  },
  {
    path: '/address',
    meta: { title: '地址管理', isAuth: true },
    component: resolve => require(['page/address'], resolve)
  },
  {
    path: '/address/manage',
    meta: { title: '地址管理', isAuth: true },
    component: resolve => require(['page/address/manage'], resolve)
  },
  {
    path: '/collect',
    meta: { title: '我的收藏', isAuth: true },
    component: resolve => require(['page/collect'], resolve)
  },
  {
    path: '/order',
    meta: { title: '我的订单', isAuth: true },
    component: resolve => require(['page/order'], resolve)
  },
  {
    path: '/search',
    meta: { title: '搜索' },
    component: resolve => require(['page/search'], resolve)
  },
  {
    path: '/search/:type',
    component: resolve => require(['page/search/list'], resolve)
  },
  {
    path: '/set',
    meta: { title: '设置', isAuth: true },
    component: resolve => require(['page/set'], resolve)
  },
  {
    path: '/footprint',
    meta: { title: '足迹', isAuth: true },
    component: resolve => require(['page/footprint'], resolve)
  },
  {
    path: '/protocol',
    component: resolve => require(['page/protocol'], resolve)
  },
  {
    path: '/hotspot/:id',
    meta: { title: '热点' },
    component: resolve => require(['page/hotspot/detail'], resolve)
  },
  {
    path: '/goods/:id',
    meta: { title: '商品详情' },
    component: resolve => require(['page/goodsDetail'], resolve)
  },
  {
    path: '/channel/:id',
    meta: { title: '频道' },
    component: resolve => require(['page/home/channel'], resolve)
  },
  {
    path: '/goodslist',
    meta: { title: '商品列表' },
    component: resolve => require(['page/home/goodsList'], resolve)
  },
  {
    path: '/cart/order',
    meta: { title: '确认订单' },
    component: resolve => require(['page/cart/confirmOrder'], resolve)
  },
  {
    path: '/cart/pay',
    meta: { title: '订单支付' },
    component: resolve => require(['page/cart/pay'], resolve)
  },
  {
    path: '/cart/success',
    meta: { title: '订单支付成功', isAuth: true },
    component: resolve => require(['page/cart/success'], resolve)
  },
  {
    path: '/classify/detail/:id/:name',
    meta: { title: '分类详情' },
    component: resolve => require(['page/classify/detail'], resolve),
  },
  {
    path: '/',
    component: resolve => require(['./App'], resolve),
    children: [
      {
        path: '/',
        meta: { title: '首页' },
        component: resolve => require(['page/home'], resolve)
      },
      {
        path: 'classify',
        meta: { title: '分类' },
        component: resolve => require(['page/classify'], resolve)
      },
      {
        path: 'hotspot',
        meta: { title: '热点' },
        component: resolve => require(['page/hotspot'], resolve)
      },
      {
        path: 'cart',
        meta: { title: '购物车' },
        component: resolve => require(['page/cart'], resolve)
      },
      {
        path: 'my',
        meta: { title: '我的' },
        component: resolve => require(['page/my'], resolve)
      }
    ]
  },
  {
    path: '/hotspot/:id',
    component: resolve => require(['page/hotspot/detail'], resolve)
  },
  {
    path: '*',
    redirect: '/'
  }
]

export default new Router({
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  mode: 'history',
  routes
})